package com.diudiutechnology.www.yadiudiu.yadiudiu.main.MyAdapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.diudiutechnology.www.yadiudiu.R;
import com.diudiutechnology.www.yadiudiu.yadiudiu.model.HomePageModel;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/8/31.
 */

public class HomePageHorizontalAdapter extends BaseAdapter {

    private Context mContext;
    List<HomePageModel.SeckillTimeBean> model= new ArrayList<>();
    public HomePageHorizontalAdapter(Context context) {
        this.mContext = context;
    }

    @Override
    public int getCount() {
        return model.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }
    public void addItem(List<HomePageModel.SeckillTimeBean> model){

        this.model=model;
        notifyDataSetChanged();
    }

    public void removeItem(int position){
        if (model.size()>0) {
            model.remove(position);
            notifyDataSetChanged();
        }
    }

    public List<HomePageModel.SeckillTimeBean> getDatas(){
        return model==null?new ArrayList<HomePageModel.SeckillTimeBean>():model;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = LayoutInflater.from(mContext).inflate(
                    R.layout.item_home_page_horizontal, null);
            holder.item_time = (TextView) convertView
                    .findViewById(R.id.item_time);

            holder.item_content = (TextView) convertView
                    .findViewById(R.id.item_content);


            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        HomePageModel.SeckillTimeBean data  = model.get(position);
        holder.item_time.setText(data.getStarttime());
        holder.item_content.setText("限时:"+data.getCountDown());
        return convertView;
    }

    class ViewHolder {

        TextView item_time;
        TextView item_content;

    }
}


